$package('itsm.system');

itsm.system.sellMain=function(){
	this.opt='';
	return {
		//列表
		sellMainGrid:function(){
			var params = $.extend({},jqGridParams, {	
				url:'sell!findSellPager.action',
				caption:'挂牌卖出列表',
				colNames:['ID','玩家账号','待处理股数','挂牌卖出股','挂牌卖出价格','已卖出股数','剩余股数','挂出时间','拆分时间','拆分的股价','拆分后股数'],
			 	colModel:[
			 	          {name:'sellId',align:'center'},
			 	          {name:'loginName',align:'center'},
			 	          {name:'pendingSellShare',align:'center'},
			 	          {name:'sellShare',align:'center'},
			 	          {name:'sellPrice',align:'center'},
			 	          {name:'alreadySellShare',align:'center'},
			 	          {name:'surplusSellShare',align:'center'},
			 	          {name:'sellDate',align:'center',formatter:timeFormatter},
			 	          {name:'splitDate',align:'center',formatter:timeFormatter},
			 	          {name:'splitSellPrice',align:'center'},
			 	          {name:'splitSellShare',align:'center'}
			 	          
			 	],
				jsonReader: $.extend(jqGridJsonReader, {id: "sellId"}),
				sortname:'sellId',
				pager:'#sellMainPager'
				});
				$("#sellMainGrid").jqGrid(params);
				$("#sellMainGrid").navGrid('#sellMainPager',navGridParams);
				//列表操作项
				$("#t_sellMainGrid").css(jqGridTopStyles);
				$("#t_sellMainGrid").html($('#sellMainGridToolbar').html());
				
				//自适应宽度
				setGridWidth("#sellMainGrid","regCenter",10);
		},
		//打开添加窗口
		openAddWin:function(){
			opt='saveSell';
			resetForm('#sellMain_add_form');
			$('#sellMain_add_win').window('open');
		},
		
		//打开编辑窗口
		openEditWin:function(){
			opt='updateSell';
			checkBeforeEditGrid('#sellMainGrid',function(rowData){
				$('#sellMain_sellId').val(rowData.sellId);
				
				$('#sellMain_pendingSellShare').val(rowData.pendingSellShare);
				$('#sellMain_sellShare').val(rowData.sellShare);
				$('#sellMain_sellPrice').val(rowData.sellPrice);
				$('#sellMain_alreadySellShare').val(rowData.alreadySellShare);
				$('#sellMain_surplusSellShare').val(rowData.surplusSellShare);
				$('#sellMain_sellDate').val(rowData.sellDate);
				$('#sellMain_loginName').val(rowData.loginName);
				$('#sellMain_sellDate').val(rowData.sellDate);
				$('#sellMain_add_win').window('open');
			});	
		},
		
		//保存
		saveSell:function(){
			if($('#sellMain_add_win').form('validate')){
				var _param = $('#sellMain_add_win form').serialize();
				$.post('sell!'+opt+'.action',_param,function(data){
					msgShow('保存成功!','show');
					$('#sellMain_add_win').window('close');
					$('#sellMainGrid').trigger('reloadGrid');
				})
				
			}
		},
		//删除
		deleteSell:function(){
			checkBeforeDeleteGrid('#sellMainGrid',function(rowIds){
				var pp = $.param({'ids':rowIds},true);
				$.post("sell!deleteSell.action", pp, function(){
					$('#sellMainGrid').trigger('reloadGrid');
					msgShow('删除成功!','show');
				}, "json");
			});
		},
		//打开搜索窗口
		openSearchWin:function(){
			$('#sellMain_search_win').window('open');
		},
		//搜索
		searchSell:function(){
			var sdata=$('#sellMain_search_win form').getForm();
			var postData = $("#sellMainGrid").jqGrid("getGridParam", "postData");
			$.extend(postData,sdata);
			var _url = 'sell!findSellPager.action';		
			$('#sellMainGrid').jqGrid('setGridParam',{url:_url}).trigger('reloadGrid',[{"page":"1"}]);
		},
		init:function(){
			itsm.system.sellMain.sellMainGrid();
		}
	}
	
}();

$(function(){
	itsm.system.sellMain.init();
});